import PinyinMatch from 'pinyin-match';
import { clog, isNull } from '/@/utils';

export const getInputWidth = (col: number) => {
	const inputStyle = ref({ width: '' });

	switch (col) {
		case 1:
			//inputStyle.value.width = ''; //参考标准, 实际不起作用, 被element plus自带的样式覆盖了(含!important)
			break;
		case 2:
			inputStyle.value.width = '450px !important';
			break;
		case 3:
			inputStyle.value.width = '560px !important';
			break;
		case 4:
			inputStyle.value.width = '684px !important';
			break;
	}

	return {
		inputStyle,
	};
};

/**
 * 根据中文拼音过滤
 * item必须有label字段
 */
export function filterArrayWithPinYin(options: any[], query: string) {
	var curOptions;
	if (!isNull(query)) {
		curOptions = options.filter((item) => {
			return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1 || PinyinMatch.match(item.label, query);
		});
	} else {
		curOptions = options;
	}
	return curOptions;
}
